<template>
  <div class="app-container">
    <div class="item2">
      <div class="header">
        <div class="title1">
          <i class="el-icon-data-analysis"></i><span>补货任务</span>
        </div>
        <div class="backB">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
        </div>
      </div>
      <div class="formCenter">
        <el-form
          :model="queryParams"
          size="large"
          :inline="true"
          ref="queryForm"
          :rules="formRules"
          label-width="120px"
        >
        <el-form-item label="任务时间:" prop="addTime">
            <el-date-picker
              v-model="addTime"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="任务编号:" prop="taskId">
            <el-input
              v-model="queryParams.taskId"
              placeholder="请输入任务编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="任务类型:" prop="taskProcessMsg">
            <el-select
              v-model="queryParams.taskProcessMsg"
              placeholder="请选择任务类型"
              clearable
            >
              <el-option
                v-for="dict in dict.type.taskprocessmsg_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="任务状态:" prop="taskprocess">
            <el-select
              v-model="queryParams.taskprocess"
              placeholder="请选择任务状态"
              clearable
            >
              <el-option
                v-for="dict in dict.type.taskprocess_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="产品编码:" prop="sku">
            <el-input
              v-model="queryParams.sku"
              placeholder="请输入产品编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="楼层:" prop="floor">
            <el-select
              v-model="queryParams.floor"
              placeholder="请选择楼层"
              clearable
            >
              <el-option
                v-for="dict in dict.type.floor_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="medium"
              @click="handleQuery"
              >搜索</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-table
        :data="tableData"
        border
        height="680"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
      >
        <!-- <el-table-column align="center" prop="floor" label="楼层">
        </el-table-column> -->
        <el-table-column align="center" prop="addTime" label="任务时间">
        </el-table-column>
        <el-table-column align="center" prop="taskId" label="任务编号">
        </el-table-column>
        <el-table-column align="center" prop="taskProcessMsg" label="任务类型">
        </el-table-column>
        <el-table-column align="center" prop="taskprocess" label="任务状态">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.taskprocess_type"
              :value="scope.row.taskprocess"
            />
          </template>
        </el-table-column>
        <el-table-column align="center" prop="sku" label="产品编码">
        </el-table-column>
        <el-table-column align="center" prop="skuDescr1" label="产品名称">
        </el-table-column>
        <el-table-column align="center" prop="planToQty" label="数量">
        </el-table-column>
        <!-- <el-table-column align="center" prop="taskType" label="任务类型">
        </el-table-column> -->
        <el-table-column align="center" prop="fmLocation" label="FM库位">
        </el-table-column>
        <el-table-column align="center" prop="planToLocation" label="TO库位">
        </el-table-column>
        <el-table-column align="center" prop="terminalNo2" label="补货滑道">
        </el-table-column>
        <el-table-column align="center" prop="moveDownBy" label="下架人员">
        </el-table-column>
        <el-table-column align="center" prop="moveDownTime" label="下架时间">
        </el-table-column>
        <el-table-column align="center" prop="closeWho" label="上架人员">
        </el-table-column>
        <el-table-column align="center" prop="closeTime" label="上架时间">
        </el-table-column>
        <el-table-column align="center" prop="difference" label="耗时">
        </el-table-column>
        <!-- <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleRelease(scope.row)"
              >释放笼车</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <div>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="handleQuery"
        />
      </div>
    </div>
    <div class="footer">
      <el-dialog
        title="操作验证"
        :visible.sync="centerDialogVisible"
        width="22%"
        left
        :close-on-click-modal="false"
      >
        <el-form
          :model="passForm"
          status-icon
          :rules="passrules"
          ref="passForm"
          label-width="60px"
          class="demo-ruleForm"
        >
          <el-form-item label="账号" prop="account">
            <el-input
              v-model="passForm.account"
              placeholder="请输入账号"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="pass">
            <el-input
              type="password"
              v-model="passForm.pass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getagvList,
  getagvedit,
  gettaskRpList,
} from "@/api/subSystem/continer";
import { getcheckCarPassword } from "@/api/subSystem/continer";
export default {
  dicts: ["floor_type", "taskprocess_type", "taskprocessmsg_type"],
  data() {
    return {
      // 密码验证
      centerDialogVisible: false,
      passForm: {
        pass: null,
        account: null,
      },
      passrules: {
        // pass: [{ validator: passwordError, trigger: "blur" }],
        pass: [{ required: true, message: "请输入密码", trigger: "blur" }],
        account: [{ required: true, message: "请输入账号", trigger: "blur" }],
      },
      // 总条数
      total: 0,
      addTime: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sku: null,
        taskId: null,
        floor: null,
        taskprocess: null,
        taskProcessMsg: null,
        // addTime: [],
      },
      formRules: {
        sku: [{ required: false, message: "请输入产品编码", trigger: "blur" }],
        // addTime: [
        //     { required: true, message: '请选择任务时间', trigger: 'change' }
        //   ]
        // addTime: [
        //   {
        //     type: "array",
        //     required: true,
        //     message: "请输入考试时间",
        //     fields: {
        //       //tpye类型试情况而定,所以如果返回的是date就改成date
        //       0: { type: "string", required: true, message: "请选择开始日期" },
        //       1: { type: "string", required: true, message: "请选择结束日期" },
        //     },
        //   },
        // ],
      },
      tableData: [],
      loading: false,
      // 笼车号传参
      boxNumber: null,
    };
  },
  mounted() {
    // this.handleQuery();
  },
  methods: {
    goBack() {
      this.$router.push("/subSystem1");
    },
    handleQuery() {
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.queryParams.params = {};
          if (null != this.addTime && "" != this.addTime) {
            this.queryParams.params["beginTime"] = this.addTime[0];
            this.queryParams.params["endTime"] = this.addTime[1];
          }
          console.log(this.queryParams);
          if (
            this.queryParams.params["beginTime"] &&
            this.queryParams.params["endTime"]
          ) {
            this.loading = true;
            gettaskRpList(this.queryParams).then((res) => {
              this.tableData = res.rows;
              this.total = res.total;
              this.loading = false;
            });
          }else{
            this.loading = false;
            this.$message.error("请先选择任务时间");
          }
        }
      });
    },
    handleRelease(row) {
      this.boxNumber = row.boxNo;
      console.log(111, row.boxNo);
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.passForm.account = null;
    },
    submit() {
      this.$refs.passForm.validate((valid) => {
        if (valid) {
          getcheckCarPassword({
            configValue: this.passForm.pass,
            configKey: this.passForm.account,
          }).then((res) => {
            if (res.msg == "car") {
              // console.log(this.boxNumber,this.passForm.account);
              getagvedit({
                boxNo: this.boxNumber,
                addWho: this.passForm.account,
              }).then((res) => {
                console.log(res);
                this.handleQuery();
              });
              this.centerDialogVisible = false;
            } else if (res.msg == "false") {
              this.$modal.msgError("账号或密码错误");
            }
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .el-icon-data-analysis::before {
    color: #00d9ff;
    margin-right: 8px;
  }
  .title1 {
    font-size: 16px;
    // margin-bottom: 15px;
    color: #808080;
    width: 170px;
    padding: 5px;
    border-bottom: 1px dotted #8ddfff;
  }
  .header {
    margin-top: -10px;
    margin-bottom: 40px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-date-editor.el-input,
    .el-date-editor.el-input__inner {
      width: 220px;
      margin-right: 20px;
    }

    .backB {
      cursor: pointer;

      img {
        width: 20%;
      }
    }
  }
  .formCenter {
    height: 62px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 40px;
  }
  .footer {
    margin-top: 20px;
    width: 100%;
    min-height: 200px;
  }
  .el-select {
    width: 240px;
}
}
</style>